//？？？？可能是个假的企业库详情
var app = new Vue({
	el: '#app',
	data: {
		assDetails: {
			list: [],
		},
		commentList: { list: [], total: 0 },
		objectId: "",
        messageval: "",
		pageHide:true,//页面显示
		userId:0,//用户id
	},
	created: function () {
		var that = this;
		if ($.getPara("userId") != "") {
            var userId = $.getPara("userId");
            that.userId = userId;
            //缓存用户ID
            $.setStorage("userId", userId);
        } else {
            if ($.getStorage("userId") && $.getStorage("userId") != "") {
                var userId = parseInt($.getStorage("userId"));
                that.userId = userId;
            }
        }
        var objectId = $.getPara('id');
        if(objectId){
            this.objectId = objectId;
            FastClick.attach(document.body);
            that.getDetails(objectId);
            that.getCommentList(objectId);
            $("#asso-news li").last().css("border-bottom", "none");
        }else{
            $.toast("没有当前页面的ID",'text')
            this.pageHide=false;
        }
	},
	methods: {
		backTop() {
			window.history.go(-1);
		},
		//获取详情
		getDetails(id) {
			var that = this;
			var id = id;
		
			$.ajax({
				type: "GET",
				url:  "/api/press/detail", //活动相关接口
				dataType: 'json',
				data: {
                    id: id,
                    userId:userId
				},
				success: function (res) {
					// 						console.log(res.data);
					// res.data.keywords = JSON.parse(res.data.keywords);
					that.assDetails = res.data;
					//that.assDetails.is_collect = 0; 
					that.$set(that.assDetails, "is_collect", 0)
				},
			})
		},
		//评论列表
		getCommentList() {
			var that = this;
			var objectId = that.objectId;
			var userId = getUserId(false);
			$.ajax({
				type: "GET",
				url:  "/api/comment/common/list",
				dataType: 'json',
				data: {
					type: 10,  //评论对象类型：1故事回忆，2话题，3学院，4协会，5媒体，6心情，7动态，8评测 9活动
					objectId: objectId,
					userId: userId,
					pageIndex: 1,
					pageSize: 6
				},
				success: function (res) {
					that.commentList = res.data;
				},
			})
		},
		//收藏
		chooseCollect() {
			//添加一个强制登录以获取userId
			if($.getPara("userId") != "" && this.userId > 0){//获取到userId字段内容并且用户id>0已登录
				var that = this;
				var userId = getUserId(true);
				var objectId = $.getPara('id');
				if (userId != false) {
					//1资讯，2供应，3求购，4设备，5印厂
					$.ajax({
						type: "POST",
						url:  "/api/collect/collect",
						dataType: 'json',
						data: {
							type: 9,
							objectId: objectId,
							userId: userId,
						},
						success: function (res) {
							if (res.code == 200) {
								$.toast("收藏成功");
								that.$set(that.assDetails, "is_collect", 1)
							}
						},
					})
				}
			}else{
				//用户未登录或者未获取到userId字段内容
				if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){ //判断iPhone|iPad|iPod|iOS
                    //默认为iOS系统   
                    window.webkit.messageHandlers.appLogin.postMessage(null);
                }else {
                    //pc
                    alert("PC浏览器-appLogin");
                };
			}
			
		},
		//取消收藏
		chanceCollect() {
			 //添加一个强制登录以获取userId
			 if($.getPara("userId") != "" && this.userId > 0){///获取到userId字段内容并且用户id>0已登录       
				var that = this;
				var userId = getUserId(true);
				var objectId = $.getPara('id');
				if (userId != false) {
					//1资讯，2供应，3求购，4设备，5印厂
					$.ajax({
						type: "POST",
						url:  "/api/collect/cancelCollect",
						dataType: 'json',
						data: {
							type: 9,
							objectId: objectId,
							userId: userId,
						},
						success: function (res) {
							if (res.code == 200) {
								$.toast("取消收藏成功", "text");
								that.$set(that.assDetails, "is_collect", 0)
							}
						},
					})
				}
			}else{
				//用户未登录
                if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){ //判断iPhone|iPad|iPod|iOS
                    //默认为iOS系统   
                    window.webkit.messageHandlers.appLogin.postMessage(null);
                }else {
                    //pc
                    alert("PC浏览器-appLogin");
                };
			}
		},
		//发表评论
		//评论对象类型：1故事回忆，2话题，3学院，4协会，5媒体，6心情，7动态
		sendMessage() {
			//添加一个强制登录以获取userId
            if($.getPara("userId") != "" && this.userId > 0){//获取到userId字段内容并且用户id>0已登录
				var that = this;
				var val = that.messageval;
				var objectId = that.objectId;
				var userId = getUserId(true);
				if (userId != false) {
					if (val == "") {
						$.toast("请填写评论", "text");
						return false;
					};
					$.ajax({
						type: "POST",
						url:  "/api/comment/common/publish",
						dataType: 'json',
						data: {
							type: 9,
							objectId: objectId,
							userId: userId,
							comment: val
						},
						success: function (res) {
							if (res.code == 200) {
								$.toast("评论成功", "text");
								that.messageval = "";
								that.getCommentList();
							}
						},
					})
				}
			}else{
				//用户未登录
                if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){ //判断iPhone|iPad|iPod|iOS
                    //默认为iOS系统   
                    window.webkit.messageHandlers.appLogin.postMessage(null);
                }else {
                //pc
                alert("PC浏览器-appLogin");
            	};
			}
		}
	}
})

